<!--
 @Author: libing/makeup1122
 @Email: makeup1123@163.com
 @Date: "2020-02-20 15:53:21"
-->
<template>
  <van-form @submit="onSubmit">
    <van-row type="flex" align="center" :style="{'height':height}">
      <van-col span='24'>
        <van-field
          v-model="username"
          name="username"
          label="用户名"
          placeholder="用户名"
          :rules="[{ required: true, message: '请填写用户名' }]"
        />
        <van-field
          v-model="password"
          type="password"
          name="password"
          label="密码"
          placeholder="密码"
          :rules="[{ required: true, message: '请填写密码' }]"
        />
        <div style="margin:16px;">
        <van-button :loading="loading" round block type="info" native-type="submit">
          登录
        </van-button>
        <van-button style="margin-top:26px;" block round :to="{ name: 'Register' }">
          注册
        </van-button>
        </div>
      </van-col>
    </van-row>
  </van-form>
</template>
<script>
export default {
  name: 'Login',
  components: {},
  data: function () {
    return {
      username: '',
      password: '',
      loading: false
    }
  },
  created: function () {

  },
  computed: {
    height: function() {
      return window.innerHeight + 'px'
    }
  },
  methods: {
    onSubmit(values) {
      this.loading = true
      this.$store.dispatch('doLogin', values).then(() => {
        this.$router.push({ path: '/' })
      }).catch(err => {
        this.$notify({ type: 'warning', message: err.response.data })
        // console.log(err.response.data)
      }).finally(() => {
        this.loading = false
      })
    }
  }
}
</script>
<style scoped>
</style>
